/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import model.entity.BranchProduct;

public class BranchProductImp {
  
    public boolean AddProduct(int branchid,int productid)
    {
        boolean kq = true;
        try {
//            Statement st = ConnectDatabase.getConnection().createStatement();
//           
//         ResultSet rs = st.executeQuery("insert into branch_product values ("+branchid+","+productid+")");
//            rs.close();
            Connection con = ConnectDatabase.getConnection();
            PreparedStatement prst = con.prepareCall("insert into branch_product values (?,?)");
            prst.setInt(1, branchid);
            prst.setInt(2, productid);
            prst.execute();
        } catch (Exception e) {
            kq = false;
        }
        return kq;
    }
        public static void main(String[] args) {
        BranchProductImp bkjjk = new BranchProductImp();
        ProductImp pim = new ProductImp();
        List<Integer> list = bkjjk.GetProductId(2);
        for(Integer i : list)
        {
            System.out.println(i);
        }
//        boolean kq = bkjjk.AddProduct(4, 26);
//        System.out.print(kq);
    }
    public List<Integer> GetProductId(int branchid)
    {
        List<Integer> list = new ArrayList<Integer>();
        try {
            Statement st = ConnectDatabase.getConnection().createStatement();
            ResultSet rs = st.executeQuery("select productid from branch_product where branchid = "+ branchid);
            while(rs.next())
            {
                list.add(rs.getInt("productid"));
            }
        } catch (Exception e) {
        }
        return list;
    }

    
}
